import { defHttp } from '@/utils/http/axios';
import { StoreApiResult, StoreInsertOrUpdateForm } from './model/StoreModel';

enum Api {
  REST = '/api/v1/stores',
}

/**
 * 商户-分页列表
 */
export const listStoreApi = (queryForm: any) => {
  // 选择的是日期，补全时分秒部分
  if (queryForm.beginAt) {
    queryForm.beginAt += ' 00:00:00';
  }

  if (queryForm.endAt) {
    queryForm.endAt += ' 23:59:59';
  }

  return defHttp.get<StoreApiResult[]>({
    url: Api.REST,
    params: queryForm,
  });
};

/**
 * 商户-详情
 */
export const retrieveStoreApi = (id: string) => {
  return defHttp.get<StoreApiResult>({
    url: `${Api.REST}/${id}`,
  });
};

/**
 * 商户-新增
 */
export const insertStoreApi = (insertForm: StoreInsertOrUpdateForm) => {
  return defHttp.post<void>({
    url: Api.REST,
    params: insertForm,
  });
};

/**
 * 商户-编辑
 */
export const updateStoreApi = (id: string, updateForm: StoreInsertOrUpdateForm) => {
  return defHttp.put<void>({
    url: `${Api.REST}/${id}`,
    params: updateForm,
  });
};

/**
 * 商户-删除
 */
export const deleteStoreApi = (ids: string[]) => {
  return defHttp.delete<void>({
    url: Api.REST,
    params: {
      ids: ids,
    },
  });
};
/**
 * 商户-分页列表
 */
export const listSelectStoreApi = (queryForm: any) => {
  return defHttp.get<StoreApiResult[]>({
    url: `${Api.REST}/list`,
    params: queryForm,
  });
};
